<?
/***************************************************************************
*                            Dolphin Smart Community Builder
*                              -------------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2007 BoonEx Notice
*     website              : http://www.boonex.com
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or  any later version.
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/

bx_import('BxDolTwigTemplate');
 
/*
 * Notices module View
 */
class BxNoticesTemplate extends BxDolTwigTemplate {

    var $_iPageIndex = 500;      
    
	/**
	 * Constructor
	 */
	function BxNoticesTemplate(&$oConfig, &$oDb) {
        parent::BxDolTwigTemplate($oConfig, $oDb);
    }

    function unit ($aData, $sTemplateName, &$oVotingView) {

        if (null == $this->_oMain)
            $this->_oMain = BxDolModule::getInstance('BxNoticesModule');

        if (!$this->_oMain->isAllowedView ($aData)) {            
            $aVars = array ('extra_css_class' => 'modzzz_notices_unit');
            return $this->parseHtmlByName('browse_unit_private', $aVars);
        }
 

        $aAuthor = getProfileInfo($aData['author_id']);

        $sImageUrl = ''; 
        $sImageTitle = ''; 
        $a = array ('ID' => $aData['author_id'], 'Avatar' => $aData['thumb']);
        $aImage = BxDolService::call('photos', 'get_image', array($a, 'file'), 'Search');

        modzzz_notices_import('Voting');
        $oRating = new BxNoticesVoting ('modzzz_notices', $aData['id']);
 
		$sOwnerThumb = get_member_thumbnail($aAuthor['ID'], 'left');  

		$sDateTime = defineTimeInterval($aData['created']);
     
		$sPostText = $aData['snippet'];

		if(!$sPostText){
			$iLimitChars = 400;
			if (strlen($sPostText) > $iLimitChars) {
				$sLinkMore = '...';
				$sPostText = process_line_output(mb_substr(strip_tags($sPostText), 0, $iLimitChars)) . $sLinkMore;
			}
		}
 
        $aVars = array (
			'id' => $aData['id'], 
			'thumb' => $sOwnerThumb,
             'notice_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
            'notice_title' => $aData['title'],
            'notice_description' => $sPostText,
            'comments_count' => $aData['comments_count'],
            'post_date' => strtolower($sDateTime), 
            'post_uthumb' => $sOwnerThumb,
            'category' => _t('_modzzz_notices_'.$aData['category']),  
            'post_tags' => $this->_oMain->parseTags($aData['tags']), 
            'author_title' => _t('_From'),
            'author_username' => $sAuthorName,
            'author_url' => $sAuthorLink,
            'rating' => $oRating->isEnabled() ? $oRating->getJustVotingElement (true, $aData['id']) : '',
            'from_date' => date("M d, Y", $aData['start']),
            'to_date' => date("M d, Y", $aData['end']),

			'bx_if:compensation' => array( 
				'condition' => getParam('modzzz_notices_allow_pay'),
				'content' => array(
					'compensation' => _t($GLOBALS['aPreValues']['NoticesCompensation'][$aData['compensation']]['LKey'])
 				) 
			),  

            'country_city' => _t($GLOBALS['aPreValues']['Country'][$aData['country']]['LKey']) . (trim($aData['city']) ? ', '.$aData['city'] : '') 

        );
 
        return $this->parseHtmlByName($sTemplateName, $aVars);
    }

    // ======================= ppage compose block functions 

    function blockDesc (&$aDataEntry) {
        $aVars = array (
            'description' => $aDataEntry['desc'],
        );
        return $this->parseHtmlByName('block_description', $aVars);
    }

    function blockFields (&$aDataEntry) {
        $sRet = '<table class="modzzz_notices_fields">';
        modzzz_notices_import ('FormAdd');        
        $oForm = new BxNoticesFormAdd ($GLOBALS['oBxNoticesModule'], $_COOKIE['memberID']);
        foreach ($oForm->aInputs as $k => $a) {
            if (!isset($a['display'])) continue;
 
            $sRet .= '<tr><td class="modzzz_notices_field_name" valign="top">'. $a['caption'] . '<td><td class="modzzz_notices_field_value">';
    
            if (is_string($a['display']) && is_callable(array($this, $a['display'])))
                $sRet .= call_user_func_array(array($this, $a['display']), array($a['listname'], $aDataEntry[$k]));	 
			else
                $sRet .= $aDataEntry[$k];
            $sRet .= '<td></tr>';
        }
        $sRet .= '</table>';
        return $sRet;
    }
 
	function getPreListDisplay($sField, $sVal){ 
 		return htmlspecialchars_adv( _t($GLOBALS['aPreValues'][$sField][$sVal]['LKey']) );
	}

	function getStateName($sVal){ 
		return $this->_oDb->getStateName($sVal);
	}


}

?>